package wd

import (
	"fmt"

	"github.com/spf13/viper"
)

// loadConfig 加载配置文件
func initConfig() {
	viper.AutomaticEnv()
	viper.SetConfigName("main")     // name of config file (without extension)
	viper.SetConfigType("yaml")     // REQUIRED if the config file does not have the extension in the name
	viper.AddConfigPath("./config") // 找寻的路径
	err := viper.ReadInConfig()     // Find and read the config file
	if err != nil {                 // Handle errors reading the config file
		panic(fmt.Errorf("fatal error config file: %w", err))
	}
	App.Config = viper.GetViper()
	fmt.Printf("加个配置文件: '%s' 成功\n", viper.ConfigFileUsed())
	App.Env = viper.GetString("app.env")
	if App.Env == "" {
		App.Env = EnvDev
	}
}
